export default {
	exportExcel(fileData, documentName = 'excel') {
		plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
			let rootObj = fs.root;
			let fullPath = rootObj.fullPath;
			// const environment = plus.android.importClass("android.os.Environment");
			
			// const baseDir = '/1龙湖四中ce/';
			// let fullPath = environment.getExternalStorageDirectory() + baseDir;
			console.log("开始导出数据")
			// 创建文件夹
			rootObj.getDirectory(documentName, {
				create: true
			}, function(dirEntry) {
				// 创建文件,防止重名
				let fileName = new Date().getTime()
				console.log(fileName)
				dirEntry.getFile(`${fileName}.xlsx`, {
					create: true
				}, function(fileEntry) {
					fileEntry.createWriter(function(writer) {
						writer.onwritestart = (e) => {
							uni.showLoading('正在导出')
						}
						writer.onwrite = (e) => {
							// 成功导出数据
							uni.hideLoading()
							setTimeout(() => {
								uni.showToast('导出成功')
								// const morenClass = uni.getStorageSync(
								// 	'默认班级');
								// const fullPath =
								// '/storage/emulated/0/1龙湖四中嘿嘿'; // 这里是你指定的文件夹路径
								// const path =
								// 	`file://${fullPath}${documentName}/学生成绩_${morenClass}.xlsx`;
								const path =
									`file://${fullPath}/${documentName}/测试${fileName}.xlsx`;
								console.log('文件位置path：', path);
								// 打开文件
								uni.openDocument({
									filePath: path,
									success: res => {
										console.log('打开文档成功',
											res)
									},
									fail: e => {
										console.log('打开失败', e)
									}
								})
							}, 500)
						}
						// 写入内容
						writer.write(fileData)
					}, function(e) {
						console.log(e.message)
					})
				})
			})
		})
	}
}